﻿@model IEnumerable<LAVAA.DAL.UserGroup>

@{
    ViewBag.Title = "Usergroups";
}

<h2>Index</h2>

<p>
    @*  @Html.ActionLink("Create New", "Create")
    @Html.ActionLink("Create", "Create", "UserGroup", null, new { @class = "openDialog", data_dialog_id = "CreateDialog", data_dialog_title = "Create group"})*@
    @Html.DialogFormLink("Create group", Url.Action("Create"), "Create group", Url.Action("Index"))
</p>
@Html.ValidationSummary(true)

<div id="divTest">

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.Id })
                @Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { onclick = "return confirm('Are you sure you want to delete " + item.Name + "?')" })
            </td>
        </tr>
    }
</table>
</div>

<p>
    @Html.ActionLink("Back", "Index", "User")
</p>

@*    <script type="text/javascript">
        $.ajaxSetup({ cache: false });
        $(document).ready(function () {
            $(".openDialog").live("click", function (e) {
                e.preventDefault();

                $.validator.unobtrusive.parse(this);

                $("<div></div>")
                    .addClass("dialog")
                    .attr("id", $(this).attr("data-dialog-id"))
                    .appendTo("body")
                    .dialog({
                        height: 300,
                        width: 400,
                        title: $(this).attr("data-dialog-title"),
                        close: function () { $(this).remove() },
                        modal: true,
                        buttons: {
                            "Save": function () {
                                // Manually submit the form                        
                                var form = $('form', this);
                                $(form).submit();
                            },
                            "Cancel": function () { $(this).dialog('close'); }
                        }
                    })
                    .load(this.href);
            });

            $(".close").live("click", function (e) {
                e.preventDefault();
                $(this).closest(".dialog").dialog("close");
            });
        });
    </script>*@